package br.com.mmm.javacenter.framework.filters;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;

import br.com.mmm.javacenter.framework.dao.HibernateUtil;

public class HibernateFilter implements Filter{
	private static Logger logger = Logger.getLogger(HibernateFilter.class);
	private FilterConfig config;

	
	public void destroy() {
		setConfig(null);
	}

	
	public void doFilter(ServletRequest request, ServletResponse response,FilterChain chain) throws IOException, ServletException {
		HibernateUtil.criarSession();
		logger.debug(((HttpServletRequest)request).getServletPath());
		chain.doFilter(request, response);
		HibernateUtil.fecharSession();
	}

	
	public void init(FilterConfig config) throws ServletException {
		this.setConfig(config);
	}


	public void setConfig(FilterConfig config) {
		this.config = config;
	}


	public FilterConfig getConfig() {
		return config;
	}

}
